import { render } from 'vue'
import XtxConfirm from './xtx-confirm.vue'

// 创建实例div存放弹框
const divVNode = <div class="xtx-confirm-container"></div>
// const divVNode = createVNode('div', { class: 'xtx-confirm-container' })
render(divVNode, document.body)
const div = divVNode.el

const Confirm = ({ title, text }) => {
  return new Promise((resolve, reject) => {
    const confirmCallBack = () => {
      resolve('点击确认')
      render(null, div)
    }
    const cancelCallBack = () => {
      reject(new Error('点击取消'))
      render(null, div)
    }
    const confirm = <XtxConfirm {...{ title, text, confirmCallBack, cancelCallBack }}></XtxConfirm>
    // const confirm = createVNode(XtxConfirm, { title, text, confirmCallBack, cancelCallBack })
    render(confirm, div)
  })
}
export default Confirm
